#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int firstMissingPositive(int* nums, int numsSize);

inline void swap(int* nums, int idx1, int idx2);

int main()
{
	int numsSize;
	scanf("%d", &numsSize);
	int* nums = calloc(numsSize, sizeof(int));
	for (int i = 0; i < numsSize; i++)
		scanf("%d", nums + i);
	int res = firstMissingPositive(nums, numsSize);
	printf("%d\n", res);
	return 0;
}

int firstMissingPositive(int* nums, int numsSize)
{
	for (int i = 0; i < numsSize; i++) {
		int num = nums[i];
		while (num >= 1 && num <= numsSize && num != i + 1 && num != nums[num - 1])
			swap(nums, i, nums[i] - 1), num = nums[i];
	}
	for (int i = 0; i < numsSize; i++)
		if (nums[i] != i + 1)
			return i + 1;
	return numsSize + 1;
}

void swap(int* nums, int idx1, int idx2)
{
	int tmp = nums[idx1];
	nums[idx1] = nums[idx2];
	nums[idx2] = tmp;
}
